<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>浏览器专用功能</title>
    <style>
        #result {
            margin: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            width: 500px;
        }
        .activex { color: blue; font-weight: bold; }
        .no-activex { color: red; }
        button {
            padding: 8px 15px;
            background: #4CAF50;
            color: white;   
            border: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <button id="actionBtn">执行浏览器操作</button>
    <div id="result">请点击按钮检测浏览器并执行操作</div>

    <script>
        var actionBtn = document.getElementById('actionBtn');
        var resultDiv = document.getElementById('result');
        
        // 检测是否支持ActiveXObject
        function supportsActiveX() {
            try {
                return !!new ActiveXObject('WScript.Shell');
            } catch (e) {
                return false;
            }
        }
        
        // 打开URL的统一方法
        function openUrl(url) {
            if (supportsActiveX()) {
                // 支持ActiveX的浏览器使用命令行方式打开Chrome
                try {
                    var shell = new ActiveXObject('WScript.Shell');
                    shell.run('cmd.exe /c start %LOCALAPPDATA%\\Google\\Chrome\\Application\\chrome.exe '+ url, 0, true);
                    return true;
                } catch (ex) {
                    console.error('ActiveX执行错误:', ex);
                    return false;
                }
            } else {
                // 不支持ActiveX的浏览器使用标准方法
                window.open(url, '_blank');
                return true;
            }
        }
        
        actionBtn.onclick = function() {
            resultDiv.innerHTML = '正在检测浏览器功能...';
            
            window.setTimeout(function() {
                try {
                    var url = 'http://www.sina.com';
                    
                    if (supportsActiveX()) {
                        resultDiv.innerHTML = '<p class="activex">检测到支持ActiveXObject的浏览器</p>';
                        
                        if (openUrl(url)) {
                            resultDiv.innerHTML += '<p class="activex">已尝试通过命令行打开Chrome浏览器</p>';
                        } else {
                            resultDiv.innerHTML += '<p class="activex" style="color:red">执行失败，尝试使用window.open</p>';
                            window.open(url, '_blank');
                        }
                    } else {
                        resultDiv.innerHTML = '<p class="no-activex">当前浏览器不支持ActiveXObject</p>';
                        window.open(url, '_blank');
                        resultDiv.innerHTML += '<p>已使用标准方法打开链接</p>';
                    }
                } catch (e) {
                    resultDiv.innerHTML = '<p style="color:red">检测错误: ' + e.message + '</p>';
                    window.open('http://www.sina.com', '_blank');
                }
            }, 100);
        };
    </script>
</body>
</html>